package com.rxyb.upms.service.logic;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.rxyb.core.constants.DbConstants;
import com.rxyb.upms.db.bean.SysMenuResouce;
import com.rxyb.upms.db.dao.SysMenuResouceMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Optional;

/**
 * @author YJH
 * @version 1.0
 * @description
 * @date 2020/6/6  14:31
 */
@Component
@Slf4j
public class SysMenuResourceLogic {

    private final SysMenuResouceMapper sysMenuResouceMapper;


    public SysMenuResourceLogic(SysMenuResouceMapper sysMenuResouceMapper) {
        this.sysMenuResouceMapper = sysMenuResouceMapper;
    }

    public Optional<List<SysMenuResouce>> findmenus(Long[] menus) {
        List<SysMenuResouce> sysMenuResouces = sysMenuResouceMapper.selectList(new QueryWrapper<SysMenuResouce>().lambda().in(SysMenuResouce::getId, menus).eq(SysMenuResouce::getRowStatus, DbConstants.ROW_STATE_VALID));
        if (null == sysMenuResouces || sysMenuResouces.isEmpty()) {
            log.info("菜单编号[{}]未查询到菜单信息", menus);
            return Optional.empty();
        }
        log.info("菜单编号[{}]查询到菜单信息[{}]", menus, JSONUtil.toJsonStr(sysMenuResouces));
        return Optional.of(sysMenuResouces);
    }
}
